package com.ruoyi.web.controller.marry;

import java.util.List;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.marry.domain.TBlessComment;
import com.ruoyi.marry.service.ITBlessCommentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言管理Controller
 *
 * @author user_marry
 * @date 2020-11-24
 */
@RestController
@RequestMapping("/marry/blessComment")
public class TBlessCommentController extends BaseController {

    @Autowired
    private ITBlessCommentService tBlessCommentService;

    /**
     * 查询留言管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBlessComment tBlessComment) {
        startPage();
        List<TBlessComment> list = tBlessCommentService.selectTBlessCommentList(tBlessComment);
        return getDataTable(list);
    }

    /**
     * 查询所有留言管理详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(TBlessComment tBlessComment) {
        startPage();
        List<TBlessComment> list = tBlessCommentService.selectTBlessComments(tBlessComment.getLoversId());
        return getDataTable(list);
    }

    /**
     * 导出留言管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:export')")
    @Log(title = "留言管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBlessComment tBlessComment) {
        List<TBlessComment> list = tBlessCommentService.selectTBlessCommentList(tBlessComment);
        ExcelUtil<TBlessComment> util = new ExcelUtil<TBlessComment>(TBlessComment.class);
        return util.exportExcel(list, "blessComment");
    }

    /**
     * 根据留言编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tBlessCommentService.selectTBlessCommentById(id));
    }

    /**
     * 新增保存留言管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:add')")
    @Log(title = "留言管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TBlessComment tBlessComment) {
        return toAjax(tBlessCommentService.insertTBlessComment(tBlessComment));
    }

    /**
     * 修改留言管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:edit')")
    @Log(title = "留言管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBlessComment tBlessComment) {
        return toAjax(tBlessCommentService.updateTBlessComment(tBlessComment));
    }

    /**
     * 删除留言管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessComment:remove')")
    @Log(title = "留言管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBlessCommentService.deleteTBlessCommentByIds(ids));
    }
}
